package com.huawei.m2m.cig.decoder.hxushen.wxushen.generate.factory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.huawei.m2m.cig.decoder.hxushen.wxushen.generate.cloud.downlinkvalue;
import com.huawei.m2m.cig.decoder.protocol.NBMessage;

public class DefaultCloudMessageFactory {
	private static final Logger LOGGER = LoggerFactory.getLogger(DefaultCloudMessageFactory.class);
	private static final DefaultCloudMessageFactory INSTANCE = new DefaultCloudMessageFactory();
	private Map<String, Class<? extends NBMessage>> messageFactory = new ConcurrentHashMap();

	public static DefaultCloudMessageFactory getInstance() {
		return INSTANCE;
	}

	public NBMessage createMessage(String paramString) {
		return createInstance((Class) this.messageFactory.get(paramString));
	}

	public String getCloudMessageRspName() {
		return null;
	}

	private NBMessage createInstance(Class<? extends NBMessage> paramClass) {
		try {
			if (paramClass != null) {
				return (NBMessage) paramClass.newInstance();
			}
		} catch (Exception localException) {
			LOGGER.error("Unexpected exception when createInstance.Exception:", localException);
		}
		return null;
	}

	private DefaultCloudMessageFactory() {
		this.messageFactory.put("downlinkvalue", downlinkvalue.class);
	}
}
